//
//  Meal.m
//  Item
//
//  Created by flannery on 2018/12/17.
//  Copyright © 2018年 flannery. All rights reserved.
//

#import "Meal.h"
@interface Meal()
@property (nonatomic, strong) NSMutableArray<Item> *items;
@end

@implementation Meal

- (NSArray *)items{
    if(_items == nil) {
        _items = [[NSMutableArray<Item> alloc]init];
    }
    return _items;
}

- (void)addItem:(id<Item>)item{
    [self.items addObject:item];
}

- (float)getCost{
    float cost = 0.0f;
    for(id<Item> item in self.items) {
        cost += [item price];
    }
//    for (id<Item> *item in self.items) {
//        cost += [item price];
//    }
    return cost;
}

- (void)showItems{
    for (id<Item> item in self.items) {
        NSLog(@"%@, %@, %f",[item name], [[item packing]pack], [item price]);
    }
}

@end
